package com.nine.demo.config;

import com.nine.demo.factory.SmsHandleFactory;
import com.nine.demo.properties.SmsProperties;
import com.nine.demo.properties.SmsTemplate;
import com.nine.demo.service.impl.AliCloudSmsServiceImpl;
import com.nine.demo.service.impl.TxCloudSmsServiceImpl;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

@AutoConfiguration
// 引入该 starter 时，将这些类通过 @Import 导入到 Spring 容器中
@Import({SmsHandleFactory.class, AliCloudSmsServiceImpl.class, TxCloudSmsServiceImpl.class})
@ConditionalOnClass(SmsTemplate.class)
@EnableConfigurationProperties(SmsProperties.class)
public class SmsAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public SmsTemplate smsTemplate() {
        return new SmsTemplate();
    }

}
